home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / lisp-faq / part2 < prev    next >
Encoding:
Text File  |  1993-06-13  |  32.9 KB  |  667 lines

  1. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!usc!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!bb3.andrew.cmu.edu!crabapple.srv.cs.cmu.edu!mkant
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Subject: FAQ: Lisp Frequently Asked Questions 2/7 [Monthly posting]
  5. Message-ID: <lisp-faq-2.text_739958452@cs.cmu.edu>
  6. Followup-To: poster
  7. Summary: Frequently asked questions about Lisp -- General Questions
  8. Sender: news@cs.cmu.edu (Usenet News System)
  9. Supersedes: <lisp-faq-2.text_737280152@cs.cmu.edu>
  10. Nntp-Posting-Host: a.gp.cs.cmu.edu
  11. Reply-To: lisp-faq@think.com
  12. Organization: School of Computer Science, Carnegie Mellon
  13. Date: Sun, 13 Jun 1993 08:00:59 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Sun, 25 Jul 1993 08:00:52 GMT
  16. Lines: 648
  17. Xref: senator-bedfellow.mit.edu comp.lang.lisp:10303 news.answers:9333 comp.answers:968
  18.  
  19. Archive-name: lisp-faq/part2
  20. Last-Modified: Mon Jun  7 17:07:50 1993 by Mark Kantrowitz
  21. Version: 1.34
  22.  
  23. ;;; ****************************************************************
  24. ;;; Answers to Frequently Asked Questions about Lisp ***************
  25. ;;; ****************************************************************
  26. ;;; Written by Mark Kantrowitz and Barry Margolin
  27. ;;; lisp-faq-2.text -- 33099 bytes
  28.  
  29. This post contains Part 2 of the Lisp FAQ.
  30.  
  31. If you think of questions that are appropriate for this FAQ, or would
  32. like to improve an answer, please send email to us at lisp-faq@think.com.
  33.  
  34. Topics Covered (Part 2):
  35.  
  36.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  37.   [2-2]   When should I use a hash table instead of an association list?
  38.   [2-3]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  39.   [2-4]   Is Lisp inherently slower than more conventional languages such as C?
  40.   [2-5]   Why does Common Lisp have "#'"?
  41.   [2-6]   How do I call non-Lisp functions from Lisp?
  42.   [2-7]   Can I call Lisp functions from other languages?
  43.   [2-8]   I want to call a function in a package that might not exist at
  44.           compile time. How do I do this?  
  45.   [2-9]   What is CDR-coding?
  46.   [2-10]  What is garbage collection?
  47.   [2-11]  How do I save an executable image of my loaded Lisp system?
  48.           How do I run a Unix command in my Lisp?
  49.           How do I get the current directory name from within a Lisp program?
  50.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  51.           other platform, and there are strange characters in the code.
  52.           What do they mean?  
  53.   [2-13]  History: Where did Lisp come from?
  54.   [2-14]  How do I find the argument list of a function?
  55.           How do I get the function name from a function object?
  56.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  57.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  58.           (i.e., gobbles any output and immediately signals EOF on
  59.           input operations)?
  60.    
  61.  
  62. Search for \[#\] to get to question number # quickly.
  63.  
  64. ----------------------------------------------------------------
  65. Subject: [2-1] Is there a GNU-Emacs interface to Lisp?
  66.  
  67. ILISP is a powerful GNU-Emacs interface to many dialects of Lisp,
  68. including Lucid, Allegro, {A}KCL, IBCL, and CMU. Written by Chris
  69. McConnell <ccm+@cs.cmu.edu> and now maintained by Ivan Vazquez
  70. <ivan@haldane.bu.edu>. It is available by anonymous ftp from
  71. haldane.bu.edu [128.197.54.25] in the directory pub/ilisp as the file
  72. ilisp.tar.Z. If you want to be on the ilisp mailing list, to hear about
  73. new releases and patches, send mail to ilisp-request@darwin.bu.edu
  74. Please send any comments or code to ilisp@darwin.bu.edu.
  75.  
  76. Franz Inc.'s GNU-Emacs/Lisp interface includes an online Common
  77. Lisp manual. It is available by license from Franz Inc. Contact
  78. info@franz.com for more information. The Emacs-Lisp interface (without
  79. the online Common Lisp reference manual and some Allegro-specific code)
  80. is available free from
  81.    ftp.uu.net:/vendor/franz/emacs/emacs-lisp-2.0.4.tar.Z
  82. There is also a mailing list, lisp-emacs-forum-request@ucbarpa.berkeley.edu.
  83. (See also [1-2] for a hardcopy version of the Common Lisp reference manual.)
  84.  
  85. The cl-shell package provides a major mode (cl-shell-mode) for running
  86. Common Lisp (CL) as an Emacs subprocess.  It provides a general
  87. mechanism for communication between CL and Emacs which does not rely
  88. on extra processes, and should therefore be easily portable to any
  89. version of CL.  Features include direct (i.e., not through a temp file)
  90. evaluation and in-package compilation of forms from lisp-mode buffers,
  91. type-ahead and a history mechanism for the cl-shell buffer, and pop-up
  92. help facilities for the CL functions documentation, macroexpand and
  93. describe.  Extensions for Lucid Common Lisp provide pop-up arglists
  94. and source file editing.  Other extensions are provided to allow
  95. editing source files of CLOS or Flavors methods.  Cl-shell is
  96. available on the Lucid tape (in the goodies directory) or via
  97. anonymous ftp from whitechapel.media.mit.edu (18.85.0.125).
  98.  
  99. Lucid includes some other Emacs-Lisp interfaces in its goodies directory.
  100.  
  101. Harlequin's LispWorks includes an Emacs-Lisp interface.
  102.  
  103. Venue's Medley has an optional EMACS Interface.
  104.  
  105. GNU-Emacs itself is available by anonymous ftp from prep.ai.mit.edu.
  106.  
  107. ----------------------------------------------------------------
  108. Subject: [2-2] When should I use a hash table instead of an association list?
  109.  
  110. Both association lists (alists) and hash tables may be used to represent
  111. tabular data. Hash tables have an O(1) running time and alists an O(n)
  112. running time, so hash tables are ultimately more efficient than
  113. alists. However, if the alists are small, they can be more efficient
  114. than hash tables, which have a large initial overhead.
  115.  
  116. In Allegro CL 4.1 [SPARC; R1], the rule of thumb is that for less than
  117. 24 elements, linear search using alists beats hashing.  In Lucid CL
  118. 4.0.1 HP 9000/700, the break-even point is at 10 elements. The
  119. break-even points vary in other lisps from as low as 4 elements to as
  120. high as 100 elements. So if you're using alists in your code, using 
  121. hash tables instead may speed up your program. 
  122.  
  123. ----------------------------------------------------------------
  124. Subject: [2-3] What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  125.  
  126. Hopefully, the only reason you need to do this is as part of trying to port
  127. some old MacLisp code to Common Lisp.  These functions predated the
  128. inclusion of strings as a first-class data type in Lisp; symbols were used
  129. as strings, and they ere EXPLODEd to allow the individual characters to be
  130. manipulated in a list.
  131.  
  132. Probably the best approximations of these are:
  133.  
  134.    (defun explode (object)
  135.      (loop for char across (prin1-to-string object)
  136.            collect (intern (string char))))
  137.  
  138.    (defun implode (list)
  139.      (read-from-string (coerce (mapcar #'character list) 'string)))
  140.  
  141. An alternate definition of EXPLODE which uses MAP instead of LOOP is:
  142.  
  143.    (defun explode (object)
  144.      (map 'list #'(lambda (char) 
  145.                     (intern (string char)))
  146.           (prin1-to-string object)))
  147.  
  148. The creation of N conses of garbage to process a string of N
  149. characters is a hideously inefficient way of doing the job.  Rewrite
  150. EXPLODE code with PRIN1-TO-STRING, or better STRING if the arguments
  151. are symbols without funny characters.  For IMPLODE, try to make its
  152. caller use strings and try to make the result usable as a string to
  153. avoid having to call INTERN or READ-FROM-STRING.
  154.  
  155. ----------------------------------------------------------------
  156. Subject: [2-4] Is Lisp inherently slower than more conventional languages
  157.                such as C?
  158.  
  159. This is a tough question to answer, as you probably expected.  In many
  160. cases, it appears to be.  Lisp does not require the programmer to specify
  161. the data type of variables, so generic arithmetic operators may have to
  162. perform type checking at runtime in order to determine how to proceed.
  163. However, Lisp code can also be denser (i.e.  there is more expressed in a
  164. single line) than many other languages: the Lisp expression (+ A B) is more
  165. powerful than the C expression A+B (the Lisp version supports bignums,
  166. rationals, and complex numbers, while the C version only supports
  167. limited-size integers and floating point); therefore, one may claim that it
  168. is reasonable that the Lisp version take longer than the C version (but
  169. don't expect everyone to accept this rationalization).  Solutions to this
  170. include hardware support (e.g. processors that support type tags in data,
  171. such as SPARC and Symbolics Lisp Machines), declarations, and specialized
  172. variants of functions (e.g. in MacLisp, + accepts and returns only fixnums,
  173. +$ accepts and returns only flonums, and PLUS is generic).
  174.  
  175. At one time, the MIT PDP-10 MacLisp compiler was compared to DEC's
  176. PDP-10 Fortran compiler.  When appropriate declarations were supplied
  177. in the Lisp code, the performance of compiled Lisp arithmetic rivaled
  178. that of the Fortran code.  It would hardly be fair to compare Lisp
  179. without declarations to Fortran, since the Fortran compiler would have
  180. more information upon which it could base its optimizations. A more
  181. recent test found that numeric code compiled with optimizations using
  182. CMU CL is within the same ballpark as highly optimized Fortran code.
  183. For unoptimized Fortran code, CMU CL was about 4 times faster.
  184. Even the speed of numeric code generated by other Lisp compilers
  185. (AKCL, Allegro, Lucid) was well within an order of magnitude of good
  186. Fortran and C compilers (although slower than CMU CL).  Inspection of
  187. the emitted C code from AKCL doesn't reveal many obvious sources of
  188. inefficiency. (Since AKCL compiles Lisp into C, there are many cases
  189. where KCL code is as fast as hand-written C code.)
  190.  
  191. See the paper peoplesparc.berkeley.edu:~ftp/pub/papers/fastlisp.ps.Z
  192. for a discussion of the speed of Lisp vis a vis Fortran or C.
  193.  
  194. Since Lisp is a good language for rapid prototyping, it is easy for a
  195. mediocre programmer (or even a good programmer, who isn't being careful) to
  196. generate a large amount of inefficient Lisp code. A good example is the use
  197. of APPEND to link successive lists together, instead of keeping a pointer
  198. to the tail of the list. Often a programmer can obtain significant
  199. speed increases by using a time/space profiler to identify the
  200. functions which waste time (often small functions which are called
  201. frequently) and rewriting those functions.
  202.      
  203. ----------------------------------------------------------------
  204. Subject: [2-5] Why does Common Lisp have "#'"?
  205.  
  206. #' is a macro-character which expands #'FOO to (FUNCTION FOO).  Symbols in
  207. Lisp have two bindings, one for values and one for functions, allowing them
  208. to represent both variables and functions, depending on context. #'FOO
  209. accesses FOO's lexical function binding in a context where the value
  210. interpretation would normally occur.  #' is also used to create lexical
  211. closures for lambda expressions. A lexical closure is a function which when
  212. invoked executes the body of the lambda-expression in the lexical
  213. environment within which the closure was created.  See pp. 115-117 of CLtL2
  214. for more details.
  215.  
  216. ----------------------------------------------------------------
  217. Subject: [2-6] How do I call non-Lisp functions from Lisp?
  218.  
  219. Most Lisp implementations for systems where Lisp is not the most common
  220. language provide a "foreign function" interface.  As of now there has been
  221. no significant standardization effort in this area.  They tend to be
  222. similar, but there are enough differences that it would be inappropriate to
  223. try to describe them all here.  In general, one uses an
  224. implementation-dependent macro that defines a Lisp function, but instead of
  225. supplying a body for the function, one supplies the name of a function written
  226. in another language; the argument list portion of the definition is
  227. generally augmented with the data types the foreign function expects and
  228. the data type of the foreign function's return value, and the Lisp
  229. interface function arranges to do any necessary conversions.  There is also
  230. generally a function to "load" an object file or library compiled in a
  231. foreign language, which dynamically links the functions in the file being
  232. loaded into the address space of the Lisp process, and connects the
  233. interface functions to the corresponding foreign functions.
  234.  
  235. If you need to do this, see the manual for your language implementation for
  236. full details.  In particular, be on the lookout for restrictions on the
  237. data types that may be passed.  You may also need to know details about the
  238. linkage conventions that are used on your system; for instance, many C
  239. implementations prepend an underscore onto the names of C functions when
  240. generating the assembler output (this allows them to use names without
  241. initial underscores internally as labels without worrying about conflicts),
  242. and the foreign function interface may require you to specify this form
  243. explicitly.
  244.  
  245. Franz Allegro Common Lisp's "Foreign Function Call Facility" is
  246. described in chapter 10 of the documentation. Calling Lisp Functions
  247. from C is treated in section 10.8.2. The foreign function interface in
  248. Macintosh Common Lisp is similar. The foreign function interface for
  249. KCL is described in chapter 10 of the KCL Report. The foreign function
  250. interfaces for Lucid on the Vax and Lucid on the Sun4 are
  251. incompatible. Lucid's interface is described in chapter 5 of the
  252. Advanced User's Guide.
  253.  
  254. ----------------------------------------------------------------
  255. Subject: [2-7] Can I call Lisp functions from other languages?
  256.  
  257. In implementations that provide a foreign function interface as described
  258. above, there is also usually a "callback" mechanism.  The programmer may
  259. associate a foreign language function name with a Lisp function.  When a
  260. foreign object file or library is loaded into the Lisp address space, it is
  261. linked with these callback functions.  As with foreign functions, the
  262. programmer must supply the argument and result data types so that Lisp may
  263. perform conversions at the interface. Note that in such foreign function
  264. interfaces Lisp is often left "in control" of things like memory
  265. allocation, I/O channels, and startup code (this is a major nuisance
  266. for lots of people).
  267.      
  268. ----------------------------------------------------------------
  269.  
  270. Subject: [2-8]  I want to call a function in a package that might not exist at
  271.                 compile time. How do I do this?
  272.  
  273. Use (funcall (find-symbol "SYMBOL-NAME" :pkg-name) ...).
  274.  
  275. ----------------------------------------------------------------
  276. Subject: [2-9]  What is CDR-coding?
  277.  
  278. CDR-coding is a space-saving way to store lists in memory.  It is normally
  279. only used in Lisp implementations that run on processors that are
  280. specialized for Lisp, as it is difficult to implement efficiently
  281. in software.  In normal list structure, each element of the
  282. list is represented as a CONS cell, which is basically two pointers (the
  283. CAR and CDR); the CAR points to the element of the list, while the CDR
  284. points to the next CONS cell in the list or NIL.  CDR-coding takes
  285. advantage of the fact that most CDR cells point to another CONS, and
  286. further that the entire list is often allocated at once (e.g. by a call to
  287. LIST).  Instead of using two pointers to implement each CONS cell, the CAR
  288. cell contains a pointer and a two-bit "CDR code".  The CDR code may contain
  289. one of three values: CDR-NORMAL, CDR-NEXT, and CDR-NIL.  If the code is
  290. CDR-NORMAL, this cell is the first half of an ordinary CONS cell pair, and
  291. the next cell in memory contains the CDR pointer as described above.  If
  292. the CDR code is CDR-NEXT, the next cell in memory contains the next CAR
  293. cell; in other words, the CDR pointer is implicitly thisaddress+1, where
  294. thisaddress is the memory address of the CAR cell.  If the CDR code is
  295. CDR-NIL, then this cell is the last element of the list; the CDR pointer is
  296. implicitly a reference to the object NIL.  When a list is constructed
  297. incrementally using CONS, a chain of ordinary pairs is created; however,
  298. when a list is constructed in one step using LIST or MAKE-LIST, a block of
  299. memory can be allocated for all the CAR cells, and their CDR codes all set
  300. to CDR-NEXT (except the last, which is CDR-NIL), and the list will only
  301. take half as much storage (because all the CDR pointers are implicit).
  302.  
  303. If this were all there were to it, it would not be difficult to implement
  304. in software on ordinary processors; it would add a small amount of overhead
  305. to the CDR function, but the reduction in paging might make up for it.  The
  306. problem arises when a program uses RPLACD on a CONS cell that has a CDR
  307. code of CDR-NEXT or CDR-NIL.  Normally RPLACD simply stores into the CDR
  308. cell of a CONS, but in this case there is no CDR cell -- its contents are
  309. implicitly specified by the CDR code, and the word that would normally
  310. contain the CDR pointer contains the next CONS cell (in the CDR-NEXT case)
  311. to which other data structures may have pointers, or the first word of some
  312. other object (in the CDR-NIL case).  When CDR-coding is used, the
  313. implementation must also provide automatic "forwarding pointers"; an
  314. ordinary CONS cell is allocated, the CAR of the original cell is copied
  315. into its CAR, the value being RPLACD'ed is stored into its CDR, and the old
  316. CAR cell is replaced with a forwarding pointer to the new CONS cell.
  317. Whenever CAR or CDR is performed on a CONS, it must check whether the
  318. location contains a forwarding pointer.  This overhead on both CAR and CDR,
  319. coupled with the overhead on CDR to check for CDR codes, is generally
  320. enough that using CDR codes on conventional hardware is infeasible.
  321.  
  322. There is some evidence that CDR-coding doesn't really save very much
  323. memory, because most lists aren't constructed at once, or RPLACD is done on
  324. them enough that they don't stay contiguous.  At best this technique can
  325. save 50% of the space occupied by CONS cells. However, the savings probably
  326. depends to some extent upon the amount of support the implementation
  327. provides for creating CDR-coded lists.  For instance, many system functions
  328. on Symbolics Lisp Machines that operate on lists have a :LOCALIZE option;
  329. when :LOCALIZE T is specified, the list is first modified and then copied
  330. to a new, CDR-coded block, with all the old cells replaced with forwarding
  331. pointers.  The next time the garbage collector runs, all the forwarding
  332. pointers will be spliced out.  Thus, at a cost of a temporary increase in
  333. memory usage, overall memory usage is generally reduced because more lists
  334. may be CDR-coded. There may also be some benefit in improved paging
  335. performance due to increased locality as well (putting a list into
  336. CDR-coded form makes all the "cells" contiguous). Nevertheless, modern
  337. Lisps tend to use lists much less frequently, with a much heavier
  338. reliance upon code, strings, and vectors (structures).
  339.  
  340. ----------------------------------------------------------------
  341. Subject: [2-10] What is garbage collection?
  342.  
  343. Garbage Collection (GC) refers to the automatic storage allocation
  344. mechanisms present in many Lisps. There are several kinds of storage
  345. allocation algorithms, but most fall within two main classes:
  346.  
  347.    1. Stop and Copy. Systems which copy active objects from "old"
  348.       storage to "new" storage and then recycle the old storage.
  349.  
  350.    2. Mark and Sweep. Systems which link together storage
  351.       used by discarded objects. 
  352.  
  353. Generational scavenging garbage collection (aka emphemeral GC) is a
  354. variation in which memory is allocated in layers, with tenured
  355. (long-lived) objects in the older layers. Rather than doing a full GC
  356. of all of memory every time more room is needed, only the last few
  357. layers are GCed during an ephemeral GC, taking much less time.
  358. Short-lived objects are quickly recycled, and full GCs are then much
  359. less frequent. It is most often used to improve the performance of
  360. stop and copy garbage collectors.  It is possible to implement
  361. ephemeral GC in mark and sweep systems, just much more difficult.
  362.  
  363. Stop and copy garbage collection provides simpler storage allocation,
  364. avoids fragmentation of memory (intermixing of free storage with used
  365. storage). Copying, however, consumes more of the address space, since up to
  366. half the space must be kept available for copying all the active objects.
  367. This makes stop and copy GC impractical for systems with a small address
  368. space or without virtual memory.  Also, copying an object requires that you
  369. track down all the pointers to an object and update them to reflect the new
  370. address, while in a non-copying system you need only keep one pointer to an
  371. object, since its location will not change. It is also more difficult to
  372. explicitly return storage to free space in a copying system.
  373.  
  374. Garbage collection is not part of the Common Lisp standard. Most Lisps
  375. provide a function ROOM which provides human-readable information about the
  376. state of storage usage. In many Lisps, (gc) invokes an ephemeral garbage
  377. collection, and (gc t) a full garbage collection.
  378.  
  379. ----------------------------------------------------------------
  380. Subject: [2-11] How do I save an executable image of my loaded Lisp system?
  381.                 How do I run a Unix command in my Lisp?
  382.                 How do I get the current directory name from within a Lisp 
  383.                 program?
  384.  
  385. There is no standard for dumping a Lisp image. Here are the
  386. commands from some lisp implementations:
  387.    Lucid:               DISKSAVE
  388.    Symbolics:           Save World  [CP command]
  389.    CMU CL:              SAVE-LISP
  390.    Franz Allegro:       EXCL:DUMPLISP (documented) 
  391.                         SAVE-IMAGE (undocumented)
  392.    Medley:              IL:SYSOUT or IL:MAKESYS
  393.    MCL:                 SAVE-APPLICATION <pathname>
  394.                           &key :toplevel-function  :creator :excise-compiler
  395.                           :size :resources :init-file :clear-clos-caches
  396.    KCL:                 (si:save-system "saved_kcl")
  397.  
  398. There is no standard for running a Unix shell command from Lisp,
  399. especially since not all Lisps run on top of Unix. Here are the
  400. commands from some Lisp implementations:
  401.    Allegro:             EXCL:RUN-SHELL-COMMAND
  402.    Lucid:               RUN-PROGRAM (name 
  403.                                      &key input output
  404.                                           error-output (wait t) arguments
  405.                                           (if-input-does-not-exist :error)
  406.                                           (if-output-exists :error)
  407.                                           (if-error-output-exists :error))
  408.    KCL:                 SYSTEM 
  409.                         For example, (system "ls -l").
  410.                         You can also try RUN-PROCESS and EXCLP, but they
  411.                         don't work with all versions of KCL.
  412.    CMU CL:              RUN-PROGRAM (program args
  413.                &key (env *environment-list*) (wait t) pty input
  414.                if-input-does-not-exist output
  415.                (if-output-exists :error) (error :output) 
  416.                (if-error-exists :error) status-hook before-execve)
  417.  
  418.  
  419. There's no standard function for finding the current directory from
  420. within a Lisp program, since not all Lisp environments have the
  421. concept of a current directory. Here are the commands from some Lisp
  422. implementations:
  423.    Lucid:               WORKING-DIRECTORY (which is also SETFable)
  424.                         PWD and CD also work
  425.    Allegro:             CURRENT-DIRECTORY (use excl:chdir to change it)
  426.    CMU CL:              DEFAULT-DIRECTORY
  427.  
  428. Allegro also uses the variable *default-pathname-defaults* to resolve
  429. relative pathnames, maintaining it as the current working directory.
  430. So evaluating (truename "./") in Allegro (and on certain other
  431. systems) will return a pathname for the current directory. Likewise,
  432. in some VMS systems evaluating (truename "[]") will return a pathname
  433. for the current directory.
  434.  
  435. To toggle source file recording and cross-reference annotations, use
  436.    Allegro:             excl:*record-source-file-info*
  437.             excl:*load-source-file-info* 
  438.             excl:*record-xref-info*
  439.             excl:*load-xref-info*
  440.    LispWorks:           (toggle-source-debugging nil)
  441.  
  442. Memory management:
  443.    CMU CL:              (bytes-consed-between-gcs)  [this is setfable]
  444.    Lucid:        (change-memory-management 
  445.                      &key growth-limit expand expand-reserved)
  446.    Allegro:        *tenured-bytes-limit*
  447.  
  448. ----------------------------------------------------------------
  449. Subject: [2-12] I'm porting some code from a Symbolics Lisp machine to some
  450.                 other platform, and there are strange characters in the code.
  451.                 What do they mean?
  452.  
  453. The Symbolics Zetalisp character set includes the following
  454. characters not present in other Lisps (^ means control):
  455.    ^]      >=      greater than or equal to
  456.    ^\      <=      less than or equal to
  457.    ^Z      !=      not equal to
  458.    ^^      ==      equivalent to 
  459.    ^E      not
  460.    ^G      pi
  461.    ^L      +/-     plus/minus
  462.    ^H      lambda
  463.    ^F      epsilon
  464.    ^W      <-->    left/right arrow
  465.    ^X      <--     left arrow
  466.    ^Y      -->     right arrow
  467.    ^A              down arrow
  468.    ^K              up arrow
  469.    ^D              up caret
  470.    ^_              down caret
  471.    ^T              forall
  472.    ^U              there exists
  473.    ^B              alpha
  474.    ^C              beta
  475.    ^I              gamma
  476.    ^J              delta
  477.    ^O              partial delta  
  478.    ^N              infinity
  479.    ^M              circle +
  480.    ^V              circle x
  481.  
  482. Other special characters to look out for are the font-change characters,
  483. which are represented as a ^F followed by a digit or asterisk. A digit
  484. means to push font #N onto the stack; an asterisk means to pop the most
  485. recent font from the stack. You can clean up the code by replacing "\^F."
  486. with "". In format statements, ^P and ^Q are used to delimit text to
  487. be printed in a particular character style.
  488.      
  489. ----------------------------------------------------------------
  490. Subject: [2-13] History: Where did Lisp come from?
  491.  
  492. John McCarthy developed the basics behind Lisp during the 1956 Dartmouth
  493. Summer Research Project on Artificial Intelligence.  He intended it as an
  494. algebraic LISt Processing (hence the name) language for artificial
  495. intelligence work. Early implementations included the IBM 704, the IBM
  496. 7090, the DEC PDP-1, the DEC PDP-6 and the DEC PDP-10. The PDP-6 and
  497. PDP-10 had 18-bit addresses and 36-bit words, allowing a CONS cell to
  498. be stored in one word, with single instructions to extract the CAR and
  499. CDR parts. The early PDP machines had a small address space, which
  500. limited the size of Lisp programs. 
  501.  
  502. Milestones in the development of Lisp:
  503.  
  504.    1956            Dartmouth Summer Research Project on AI.
  505.  
  506.    1960-65         Lisp1.5 is the primary dialect of Lisp.
  507.  
  508.    1964-           Development of BBNLisp at BBN.
  509.  
  510.    late 60s        Lisp1.5 diverges into two main dialects:
  511.                    Interlisp (originally BBNLisp) and MacLisp.
  512.  
  513.    early 70s       Development of special-purpose computers known as Lisp
  514.                    Machines, designed specificly to run Lisp programs. 
  515.                    Xerox D-series Lisp Machines run Interlisp-D. 
  516.                    Early MIT Lisp Machines run Lisp Machine Lisp 
  517.                    (an extension of MacLisp).
  518.  
  519.    1969            Anthony Hearn and Martin Griss define Standard Lisp to
  520.                    port REDUCE, a symbolic algebra system, to a variety
  521.                    of architectures.  
  522.  
  523.    late 70s        Macsyma group at MIT developed NIL (New Implementation
  524.                    of Lisp), a Lisp for the VAX.
  525.  
  526.                    Stanford and Lawrence Livermore National Laboratory
  527.                    develop S-1 Lisp for the Mark IIA supercomputer.
  528.  
  529.                    Franz Lisp (dialect of MacLisp) runs on stock-hardware
  530.                    Unix machines.
  531.  
  532.                    Gerald J. Sussman and Guy L. Steele developed Scheme,
  533.                    a simple dialect of Lisp with lexical scoping and
  534.                    lexical closures, continuations as first-class objects,
  535.                    and a simplified syntax (i.e., only one binding per symbol).
  536.  
  537.                    Advent of object-oriented programming concepts in Lisp.
  538.                    Flavors was developed at MIT for the Lisp machine,
  539.                    and LOOPS (Lisp Object Oriented Programming System) was
  540.                    developed at Xerox. 
  541.  
  542.    early 80s       Development of SPICE-Lisp at CMU, a dialect of MacLisp
  543.                    designed to run on the Scientific Personal Integrated
  544.                    Computing Environment (SPICE) workstation.
  545.  
  546.    1980            First biannual ACM Lisp and Functional Programming Conf.
  547.  
  548.    1981            PSL (Portable Standard Lisp) runs on a variety of platforms.
  549.  
  550.    1981+           Lisp Machines from Xerox, LMI (Lisp Machines Inc) 
  551.                    and Symbolics available commercially.
  552.  
  553.    April 1981      Grass roots definition of Common Lisp as a description
  554.                    of the common aspects of the family of languages (Lisp
  555.                    Machine Lisp, MacLisp, NIL, S-1 Lisp, Spice Lisp, Scheme). 
  556.                    
  557.  
  558.    1984            Publication of CLtL1. Common Lisp becomes a de facto 
  559.                    standard.
  560.  
  561.    1986            X3J13 forms to produce a draft for an ANSI Common Lisp
  562.                    standard. 
  563.  
  564.    1987            Lisp Pointers commences publication.
  565.  
  566.    1990            Steele publishes CLtL2 which offers a snapshot of
  567.                    work in progress by X3J13.  (Unlike CLtL1, CLtL2
  568.                    was NOT an output of the standards process and was
  569.                    not intended to become a de facto standard.  Read
  570.                    the Second Edition Preface for further explanation
  571.                    of this important issue.) Includes CLOS,
  572.                    conditions, pretty printing and iteration facilities. 
  573.  
  574.    1992            X3J13 creates a draft proposed American National
  575.                    Standard for Common Lisp. This document is the
  576.                    first official successor to CLtL1. 
  577.  
  578. [Note: This summary is based primarily upon the History section of the
  579. draft ANSI specification. More detail and references can be obtained from
  580. that document. See [4-12] for information on obtaining a copy.]
  581. ----------------------------------------------------------------
  582. Subject: [2-14]  How do I find the argument list of a function?
  583.                  How do I get the function name from a function object?
  584.  
  585. There is no standard way to find the argument list of a function,
  586. since implementations are not required to save this information.
  587. However, many implementations do remember argument information, and
  588. usually have a function that returns the lambda list. Here are the
  589. commands from some Lisp implementations:
  590.  
  591.    Lucid:                               arglist
  592.    Allegro:                             excl::arglist
  593.    Symbolics:                           arglist
  594.  
  595. CMU Common Lisp, new compiler:
  596.    #+(and :CMU :new-compiler)
  597.    (defun arglist (name)
  598.      (let* ((function (symbol-function name))
  599.             (stype (system:%primitive get-vector-subtype function)))
  600.        (when (eql stype system:%function-entry-subtype)
  601.          (cadr (system:%primitive header-ref function
  602.                                   system:%function-entry-type-slot)))))
  603.  
  604. If you're interested in the number of required arguments you could use
  605.  
  606.    (defun required-arguments (name)
  607.      (or (position-if #'(lambda (x) (member x lambda-list-keywords))
  608.                       (arglist name))
  609.          (length (arglist name))))
  610.  
  611. To extract the function name from the function object, as in
  612.         (function-name #'car) ==> 'car
  613. use the following vendor-dependent functions:
  614.  
  615.    Symbolics: (si::compiled-function-name <fn>)
  616.     (unless (si:lexical-closure-p <fn>) ...)
  617.    Lucid:     (sys::procedure-ref <fn> SYS:PROCEDURE-SYMBOL)
  618.     (when (sys:procedurep <fn>) ..)
  619.    Allegro:   (xref::object-to-function-name <fn>)
  620.    CMU CL:    (kernel:%function-header-name <fn>)
  621.    AKCL:      (system::compiled-function-name <fn>)
  622.    MCL:       (ccl::function-name <fn>)
  623.    Harlequin: (system::function-name <fn>)
  624.  
  625. If a vendor-dependent function does not exist, the following
  626. (inefficient) code maps over all symbols looking for one whose
  627. function-cell matches the function object.
  628.  
  629. (defun function-name (fobject)
  630.    (do-all-symbols (fsymbol)
  631.       (when (and (fboundp fsymbol)
  632.                  (eq (symbol-function fsymbol) fobject))
  633.         (return fsymbol))))
  634.  
  635. If a vendor supports FUNCTION-LAMBDA-EXPRESSION, the third value is
  636. the name of the function, if available.
  637.  
  638. ----------------------------------------------------------------
  639. Subject: [2-15] How can I have two Lisp processes communicate via unix sockets?
  640.  
  641. CLX uses Unix sockets to communicate with the X window server. Look at
  642. the following files from the CLX distribution for a good example of
  643. using Unix sockets from Lisp:
  644.         defsystem.lisp          Lucid, AKCL, IBCL, CMU.
  645.         socket.c, sockcl.lisp   AKCL, IBCL
  646.         excldep.lisp            Franz Allegro CL
  647. You will need the "socket.o" files which come with Lucid and Allegro.
  648. To obtain CLX, see the entry for CLX in the answer to question [7-1].
  649.  
  650. See the file lisp-sockets.text in the Lisp Utilities repository
  651. described in the answer to question [6-1].
  652.  
  653. ----------------------------------------------------------------
  654. Subject: [2-16]  How can I create a stream that acts like UNIX's /dev/null
  655.                  (i.e., gobbles any output and immediately signals EOF on
  656.                  input operations)?
  657.  
  658. (defparameter *dev-null*
  659.   #-lispm
  660.   (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream))
  661.   ;; Since Lisp Machines have a built-in /dev/null which handles
  662.   ;; additional, non-standard operations, we'll use that instead.
  663.   #+lispm #'system:null-stream)
  664.  
  665. ----------------------------------------------------------------
  666. ;;; *EOF*
  667.